package com.ftar.urgent.ui;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.KeyEvent;

import androidx.databinding.DataBindingUtil;
import androidx.databinding.ViewDataBinding;

import com.alibaba.android.arouter.launcher.ARouter;
import com.ftar.urgent.R;
import com.ftar.urgent.constant.ArouterConstant;
import com.ftar.urgent.databinding.ActivityMainBinding;
import com.ftar.urgent.service.AsrService;
import com.ftar.urgent.viewmodel.CommonEvent;
import com.ftar.urgent.viewmodel.SP_Constants;

import org.greenrobot.eventbus.EventBus;

public class MainActivity extends BaseActivity {
    private String TAG = getClass().getSimpleName();
    private Context mContext;
    private ActivityMainBinding mBinding;
    public static final String TAG_EXIT = "tag2exit";

    private static final String mEndRecord = "结束录制";
    private static final String mStartRecord = "开始录制";


    @Override
    protected ViewDataBinding getChildBinding() {
        mBinding = DataBindingUtil.inflate(getLayoutInflater(), R.layout.activity_main, null, false);
        return mBinding;
    }

    @Override
    protected String voiceHint() {
        return "";
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        mContext = this;

        startService();
        ARouter.getInstance()
                .build(ArouterConstant.CATALOG_FIRST_ACTIVITY)
                .navigation();

    }

    private void startService() {
        Intent asrService = new Intent(this, AsrService.class);
        this.startService(asrService);
    }

    @Override
    public boolean onKeyDown(int keyCode, KeyEvent event) {
        super.onKeyDown(keyCode, event);
        CommonEvent commonEvent = new CommonEvent(SP_Constants.EVENT_SYSTEM_KEY);
        commonEvent.setData(String.valueOf(keyCode));
        EventBus.getDefault().post(commonEvent);
        return true;
    }


    @Override
    protected void onNewIntent(Intent intent) {
        super.onNewIntent(intent);
        if (intent != null) {
            boolean isExit = intent.getBooleanExtra(TAG_EXIT, false);
            if (isExit) {
                this.finish();
            }
        }
    }

    @Override
    protected void onPause() {
        super.onPause();
    }
}